export default function (G6: any) {
	const lineDash = [4, 2, 1, 2];

	// 自定义曲线
	G6.registerEdge(
		'myCubicHorizontal',
		{
			options: {
				style: {
					stroke: '#2beded',
					endArrow: true,
				},
			},
			// 响应状态变化
			setState(name: string, value: any, item: any) {
				const group = item.getContainer();
				if (!group.get('children')) return;
				const shape = group.get('children')[0]; // 顺序根据 draw 时确定
				if (name === 'selected' || name === 'active') {
					if (value) {
						shape.attr('lineWidth', 3);
					} else {
						shape.attr('lineWidth', 1.2);
					}
				}
				if (name === 'running') {
					if (value) {
						let index = 0;
						shape.animate(
							() => {
								index++;
								if (index > 9) {
									index = 0;
								}
								const res = {
									lineDash,
									lineDashOffset: -index,
								};
								// return the params for this frame
								return res;
							},
							{
								repeat: true, // 动画重复
								duration: 10000, // 一次动画的时长
							}
						);
					} else {
						// 结束动画
						shape.stopAnimate();
						shape.attr('lineDash', null);
					}
				}
			},
		},
		'cubic-horizontal'
	);
}
